<template>
  <div>
    <el-container style="background: #f5f7f9;">
      <el-header style="background: #fff;padding: 12px 12px;height:auto;">
        <div>
          <el-form :model="queryData" :inline="true" size="small">
            <el-form-item>
              <el-radio-group v-model="queryData.exceptionType" size="small" type="el-button" @change="settlementStatusChange">
                <el-radio-button label="1">计费异常</el-radio-button>
                <el-radio-button label="2">扣费异常</el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item :span="6" style="padding-right:10px">
              <el-input v-model="refNumber" type="textarea" :rows="1" style="width: 300px;" placeholder="订单号" />
            </el-form-item>
            <el-form-item :span="6" style="padding-right:10px">
              <el-button type="primary" @click="list">搜索</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-header>
      <el-main style="margin-top: 15px; background: #fff;padding: 12px 16px 0 16px;height: 100%;">
        <el-table :data="table_body" border stripe :max-height="tableHeight">
          <el-table-column prop="orderNumber" label="订单号" />
          <el-table-column prop="orgOwnerName" label="客户" />
          <el-table-column prop="productName" label="产品" />
          <el-table-column prop="exceptionMessage" label="异常" />
          <el-table-column prop="at" label="时间" />
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button v-if="queryData.exceptionType === '1'" v-has="60601" shape="circle" @click="retry(scope.row)">重新计费</el-button>
              <el-button v-else v-has="60602" shape="circle" @click="retry(scope.row)">重新扣费</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
      <el-footer style="padding:0;background: #fff;">
        <div style="text-align: right; padding-top: 10px;">
          <el-pagination background :current-page="queryData.currentPage" :page-sizes="[50,100]" :page-size="queryData.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageTotal" style="float:right;" @size-change="onPageSizeChange" @current-change="onPageChange" />
        </div>
      </el-footer>
    </el-container>
  </div>
</template>
<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      table_body: [

      ],
      styles: {
        height: 'calc(100% - 55px)',
        overflow: 'auto',
        paddingBottom: '53px',
        position: 'static'
      },
      formDataDefault: {
        currency: '',
        amount: '',
        bankCardNumber: '',
        bankRecept: '',
        remark: ''
      },
      formData: {
        txId: '',
        exchangeAmount: '',
        exchangeRate: '',
        currency: '',
        amount: '',
        bankCardNumber: '',
        bankRecept: '',
        remark: ''
      },
      queryData: {
        pageSize: 50,
        currentPage: 0,
        orderIds: [],
        exceptionType: '1'
      },
      refNumber: '',
      pageTotal: 0,
      pageSizeOpts: [50, 100]
    }
  },
  computed: {
    tableHeight() {
      return document.documentElement.clientHeight - 260
    },
    pageSize() {
      return this.pageSizeOpts[0]
    }
  },
  created() {
    this.list()
  },
  mounted() {
  },
  methods: {
    list() {
      if (this.refNumber) {
        this.queryData.orderIds = this.refNumber.split(/\n|,|，/)
      } else {
        this.queryData.orderIds = []
      }
      request({
        url: 'charge/exception/query',
        method: 'post',
        data: this.queryData
      }).then(res => {
        if (res.success) {
          if (res.data) {
            this.table_body = res.data.records
            this.pageTotal = res.data.total
          }
        }
      })
    },
    retry(row) {
      const _this = this
      const data = {
        orderId: row.orderId,
        exceptionType: this.queryData.exceptionType
      }
      if (row.id) {
         data.txIds = [row.id]
      }
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })

      request({
        url: 'charge/exception/process',
        method: 'post',
        data: data
      }).then(res => {
        setTimeout(() => {
          loading.close()
          _this.list()
        }, 3000)
      })
    },
    settlementStatusChange() {
      this.list()
    },
    onPageSizeChange(pageSize) {
      this.queryData.pageSize = pageSize
      this.list()
    },
    onPageChange(page) {
      this.queryData.currentPage = page
      this.list()
    }
  }
}
</script>
